//
//  NHBaseViewController.m
//  LZNeiHan
//
//  Created by 梁梓烽 on 16/9/28.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "NHBaseViewController.h"
#import <AFNetworkReachabilityManager.h>
#import <SDImageCache.h>
#import <YYWebImage.h>
@interface NHBaseViewController ()

@end

@implementation NHBaseViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [UIView setAnimationsEnabled:YES];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
     NSArray *gestures =self.view.gestureRecognizers;
    
    for (UIGestureRecognizer *gesture in gestures) {
        if ([gesture isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
           
            for (UIView *view in self.view.subviews) {
               
                if ([view isKindOfClass:[UIScrollView class]]) {
                    
                   UIScrollView *sc =  (UIScrollView *)view;
                    
                    [sc.panGestureRecognizer requireGestureRecognizerToFail:gesture];
                }
            }   
        
        }
    }

}


-(void)pop
{
    if (self.navigationController == nil) {
        return;
    }
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)popToRootVc
{
    if (self.navigationController == nil) {
        return;
    }
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)popToVc:(UIViewController *)vc
{
    if ([vc isKindOfClass:[UIViewController class] ]== NO) {
        return;
    }
    
    if (self.navigationController ==nil) {
        return;
    }
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}


-(void)dismiss
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)dismissWithCompletion:(void(^)())completion
{
    [self dismissViewControllerAnimated:YES completion:completion];
}

-(void)presentVC:(UIViewController *)vc
{    if ([vc isKindOfClass:[UIViewController class]] == NO) return;
    [self presetVC:vc completion:nil];
}

-(void)presetVC:(UIViewController *)vc completion:(void(^)())completion
{
    if ([vc isKindOfClass:[UIViewController class]] == NO) return;
 
    [self presentViewController:vc animated:YES completion:completion];
}

-(void)push:(UIViewController *)vc
{
    if (self.navigationController == nil) return;
    if ([vc isKindOfClass:[UIViewController class]] == NO) return;
    
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)removeChildVC:(UIViewController *)childVc;
{
   if ([childVc isKindOfClass:[UIViewController class]] == NO) return;
    
    [childVc willMoveToParentViewController:nil];
    [childVc removeFromParentViewController];
    [childVc.view removeFromSuperview];
  }

-(void)addChildVC:(UIViewController *)childVc
{
    if ([childVc isKindOfClass:[UIViewController class]] == NO) return;
    
    [childVc willMoveToParentViewController:self];
    [self addChildViewController:childVc];
    [self.view addSubview:childVc.view];
    childVc.view.frame = self.view.bounds;
    
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}


-(void)showLoadingAnimation
{
    
}

-(void)hideLoadingAnimation
{
    
}

/** 交给子类去实现 */
-(void)loadData
{
    
    
}


#pragma mark -控制器的view

-(void)viewDidLoad{
    [super viewDidLoad];
    [UIView setAnimationsEnabled:YES];

}

-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
 
    
}

- (void)dealloc
{
    
}


-(BOOL)isNetWorkReachable
{
  return  [AFNetworkReachabilityManager sharedManager].isReachable;
}


-(void)didReceiveMemoryWarning
{
    [[SDImageCache sharedImageCache]setValue:nil forKey:@"memCache"];
    
    [[[YYWebImageManager sharedManager]cache].diskCache removeAllObjects];
    
    [[[YYWebImageManager sharedManager]cache].memoryCache removeAllObjects];
}

@end
